/**
 *  @file IPCSocket.h
 */
#ifndef _IPCSOCKET_H_
#define _IPCSOCKET_H_

#include "../common/BaseObject.h"
#include "../common/CppMemPool.h"
#include "../text/CFString.h"

namespace cppflib
{

namespace net
{

//! forward declaration of IPC socket context
typedef struct _ipcsockcontext ipcsockcontext_t;

/**
 *  A socket class for communication between 2 processes on the same machine.
 *  Note that this socket supports one to one mapping only, i.e. one server socket can 
 *  only serve one client socket.
 *  After accepting a client, server socket has to disconnect by DisconnectClient before
 *  accepting another client.
 */
class _DLLAPI IPCSocket : public BaseObject 
{
private:
    ipcsockcontext_t * pContext;

public:
	IPCSocket(void);
    explicit IPCSocket(const CFString &socketName);
	virtual ~IPCSocket(void);

    void Create();
    bool Accept(int timeout);
    bool Connect(const CFString &socketName, int timeout);
    int Receive(int timeout, u8_t * pBuf, int bufLen);
    int Send(const u8_t * pBuf, int bufLen);
    void DisconnectClient();
    void Close();

    bool IsServer();
    const CFString GetSocketName();
    const CFString GetFullSocketName();
};

} // end of namespace net

} // end of namespace cppflib


#endif
